package com.ptrans.modele;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * Class for User model.
 * @author Jean
 *
 */
public class User implements Parcelable {
	
	private String regId;
	private String name;
	private String picture;
	private int position;
	private int health;
	
	private static int MAX_POS = 3;
	private static int MIN_POS = 0;
	private static int MAX_HEALTH = 2;
	private static int MIN_HEALTH = 0;

	public User() {
		
	}
	
	public User(String aRegId, String aName, String aMail, String picPath, int aPosition, int aHealth) {
		regId = aRegId;
		name = aName;
		picture = picPath;
		position = aPosition;
		health = aHealth;
	}
	
	/**
	 * Construct user from Parcel object.
	 * @param in
	 */
	public User(Parcel in) {
		regId = in.readString();
		name = in.readString();
		picture = in.readString();
		position = in.readInt();
		health = in.readInt();
	}

	public String getPicture() {
		return picture;
	}

	public void setPicture(String picturePath) {
		this.picture = picturePath;
	}

	public String getRegId() {
		return regId;
	}

	public void setRegId(String regId) {
		this.regId = regId;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	public int getPosition() {
		return position;
	}

	public void setPosition(int position) {
		this.position = position;
	}

	public int getHealth() {
		return health;
	}

	public void setHealth(int health) {
		this.health = health;
	}
	
	public boolean setPlusPosition() {
		if(position+1 <= MAX_POS) {
			setPosition(position+1);
			return true;
		} return false;
	}
	
	public boolean setMinusPosition() {
		if(position-1 >= MIN_POS) {
			setPosition(position-1);
			return true;
		} return false;
	}
	
	public boolean setPlusHealth() {
		if(health+1 <= MAX_HEALTH) {
			setHealth(health+1);
			return true;
		} return false;
	}
	
	public boolean setMinusHealth() {
		if(health-1 >= MIN_HEALTH) {
			setHealth(health-1);
			return true;
		} return false;
	}
	
	public String toString() {
		return 	"regId => " + regId + "\n" +
				"name => " + name + "\n" +
				"position => " + position + "\n" +
				"health => " + health + "\n" +
				"picture => " + picture + "\n";
	}

	@Override
	public int describeContents() {
		// TODO Auto-generated method stub
		
		return 0;
	}

	@Override
	public void writeToParcel(Parcel arg0, int arg1) {
		// TODO Auto-generated method stub
		arg0.writeString(regId);
		arg0.writeString(name);
		arg0.writeString(picture);
		arg0.writeInt(position);
		arg0.writeInt(health);
	}
	
	public static final Parcelable.Creator<User> CREATOR = new Parcelable.Creator<User>() {
		public User createFromParcel(Parcel in) {
			return new User(in);
		}
		public User[] newArray(int size) {
			return new User[size];
		}
	};
	
	

}
